package com.action;


import java.io.IOException;
import java.io.PrintWriter;
import java.text.ParseException;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import com.dao.FieldDao;
import com.dao.RecordDao;
import com.dao.TongjiDao;
import com.dao.UserDao;
import com.dao.YuyueDao;
import com.model.Field;
import com.model.Record;
import com.model.Tongji;
import com.model.User;
import com.model.Yuyue;
import com.opensymphony.xwork2.ActionSupport;
import com.util.Pager;
import com.util.Util;



public class ManageAction extends ActionSupport {

	private static final long serialVersionUID = -4304509122548259589L;



	private String url = "./";

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}


	// 获取请求对象
	public HttpServletRequest getRequest() {
		HttpServletRequest request = ServletActionContext.getRequest();
		return request;
	}

	// 获取响应对象
	public HttpServletResponse getResponse() {
		HttpServletResponse response = ServletActionContext.getResponse();
		return response;
	}

	// 获取session对象
	public HttpSession getSession() {
		HttpServletRequest request = ServletActionContext.getRequest();
		HttpSession session = request.getSession();
		return session;
	}

	// 获取输出对象
	public PrintWriter getPrintWriter() {

		HttpServletResponse response = ServletActionContext.getResponse();
		response.setCharacterEncoding("utf-8");
		response.setContentType("text/html; charset=utf-8");
		PrintWriter writer = null;
		try {
			writer = response.getWriter();
		} catch (IOException e) {
			e.printStackTrace();
		}

		return writer;
	}

	private UserDao userDao;

	public UserDao getUserDao() {
		return userDao;
	}

	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
	}

//	登入请求
	public String login() throws IOException {
		HttpServletRequest request = this.getRequest();
		PrintWriter writer = this.getPrintWriter();
		String username = request.getParameter("username");
		String password = request.getParameter("password");
		User user = userDao.selectBean(" where username = '" + username
				+ "' and password= '" + password + "' and deletestatus=0 ");
		if (user != null) {
			HttpSession session = request.getSession();
			session.setAttribute("user", user);
			this.setUrl("index.jsp");

			return "redirect";
		} else {
			writer.print("<script language=javascript>alert('用户名或者密码错误');window.location.href='login.jsp';</script>");
		}
		return null;
	}


//	用户退出
	public String loginout() {
		HttpServletRequest request = this.getRequest();
		HttpSession session = request.getSession();
		session.removeAttribute("user");
		this.setUrl("login.jsp");
		return SUCCESS;
	}

//	跳转到修改密码页面
	public String changepwd() {
		this.setUrl("password.jsp");
		return SUCCESS;
	}

//	修改密码操作
	public void changepwd2() throws IOException {
		HttpServletRequest request = this.getRequest();
		PrintWriter writer = this.getPrintWriter();
		HttpSession session = request.getSession();
		User u = (User)session.getAttribute("user");
		String password1 = request.getParameter("password1");
		String password2 = request.getParameter("password2");
		User bean = userDao.selectBean(" where username= '"+u.getUsername()+"' and password= '"+password1+"' and deletestatus=0");
		if(bean!=null){
			bean.setPassword(password2);
			userDao.updateBean(bean);
			writer.print("<script language=javascript>alert('修改成功');window.location.href='method!changepwd';</script>");

		}else{
			writer.print("<script language=javascript>alert('原密码错误');window.location.href='method!changepwd';</script>");
		}
	}



	//用户列表
	public String userlist() {
		HttpServletRequest request = this.getRequest();

		String username = request.getParameter("username");
		String xingming = request.getParameter("xingming");


		StringBuffer sb = new StringBuffer();
		sb.append(" where ");

		if (username != null && !"".equals(username)) {

			sb.append("username like '%" + username + "%'");
			sb.append(" and ");
			request.setAttribute("username", username);
		}

		if (xingming != null && !"".equals(xingming)) {

			sb.append("xingming like '%" + xingming + "%'");
			sb.append(" and ");
			request.setAttribute("xingming", xingming);
		}



		sb.append("   deletestatus=0  and role=2 order by id desc ");
		String where = sb.toString();


		int currentpage = 1;
		int pagesize = 10;
		if (request.getParameter("pagenum") != null) {
			currentpage = Integer.parseInt(request.getParameter("pagenum"));
		}
		int total = userDao.selectBeanCount(where.replaceAll(" order by id desc ", ""));
		request.setAttribute("list", userDao.selectBeanList((currentpage - 1)
				* pagesize, pagesize, where));
		request.setAttribute("pagerinfo", Pager.getPagerNormal(total, pagesize,
				currentpage, "method!userlist", "共有" + total + "条记录"));
		request.setAttribute("url", "method!userlist");
		request.setAttribute("url2", "method!user");
		request.setAttribute("biaoti", "用户管理");
		this.setUrl("user/userlist.jsp");
		return SUCCESS;

	}

//	跳转到添加用户页面
	public String useradd() {
		HttpServletRequest request = this.getRequest();
		request.setAttribute("url", "method!useradd2");
		request.setAttribute("biaoti", "用户添加");
		this.setUrl("user/useradd.jsp");
		return SUCCESS;
	}


//	添加用户操作
	public void useradd2() throws IOException {
		HttpServletRequest request = this.getRequest();
		PrintWriter writer = this.getPrintWriter();


		String username = request.getParameter("username");
		String tel = request.getParameter("tel");
		String xingming = request.getParameter("xingming");

		User bean = userDao.selectBean(" where deletestatus=0 and username='"+username+"' ");

		if(bean!=null){

			writer.print("<script language=javascript>alert('操作失败，该用户名已经存在');window.location.href='method!userlist';</script>");
			return;
		}

		bean = new User();

		bean.setCreatetime(Util.getTime());
		bean.setPassword("111111");
		bean.setRole(2);
		bean.setTel(tel);
		bean.setUsername(username);
		bean.setXingming(xingming);


		userDao.insertBean(bean);


		writer.print("<script language=javascript>alert('操作成功');window.location.href='method!userlist';</script>");


	}


//	跳转到更新用户页面
	public String userupdate() {
		HttpServletRequest request = this.getRequest();
		User bean = userDao.selectBean(" where id= "
				+ request.getParameter("id"));

		request.setAttribute("bean", bean);
		request.setAttribute("url", "method!userupdate2?id="+bean.getId());
		request.setAttribute("biaoti", "用户更新");
		this.setUrl("user/userupdate.jsp");
		return SUCCESS;
	}

//	更新用户操作
	public void userupdate2() throws IOException {
		HttpServletRequest request = this.getRequest();
		PrintWriter writer = this.getPrintWriter();


		String tel = request.getParameter("tel");
		String xingming = request.getParameter("xingming");


		User bean = userDao.selectBean(" where id= "
				+ request.getParameter("id"));

		bean.setTel(tel);
		bean.setXingming(xingming);


		userDao.updateBean(bean);

		writer.print("<script language=javascript>alert('操作成功');window.location.href='method!userlist';</script>");
	}


//	删除用户操作
	public void userdelete() throws IOException {
		HttpServletRequest request = this.getRequest();
		PrintWriter writer = this.getPrintWriter();
		User bean = userDao.selectBean(" where id= "
				+ request.getParameter("id"));
		bean.setDeletestatus(1);
		userDao.updateBean(bean);



		writer.print("<script language=javascript>alert('操作成功');window.location.href='method!userlist';</script>");
	}



	//跳转到查看用户页面
	public String userupdate3() {
		HttpServletRequest request = this.getRequest();
		User bean = userDao.selectBean(" where id= "
				+ request.getParameter("id"));
		request.setAttribute("bean", bean);
		request.setAttribute("biaoti", "用户查看");
		this.setUrl("user/userupdate3.jsp");
		return SUCCESS;
	}


	private FieldDao fieldDao;

	public FieldDao getFieldDao() {
		return fieldDao;
	}

	public void setFieldDao(FieldDao fieldDao) {
		this.fieldDao = fieldDao;
	}



	//澡堂列表
	public String fieldlist() {
		HttpServletRequest request = this.getRequest();

		String bianhao = request.getParameter("bianhao");
		String mingchen = request.getParameter("mingchen");


		StringBuffer sb = new StringBuffer();
		sb.append(" where ");

		if (bianhao != null && !"".equals(bianhao)) {

			sb.append("bianhao like '%" + bianhao + "%'");
			sb.append(" and ");
			request.setAttribute("bianhao", bianhao);
		}

		if (mingchen != null && !"".equals(mingchen)) {

			sb.append("mingchen like '%" + mingchen + "%'");
			sb.append(" and ");
			request.setAttribute("mingchen", mingchen);
		}



		sb.append("   deletestatus=0   order by id desc ");
		String where = sb.toString();


		int currentpage = 1;
		int pagesize = 10;
		if (request.getParameter("pagenum") != null) {
			currentpage = Integer.parseInt(request.getParameter("pagenum"));
		}
		int total = fieldDao.selectBeanCount(where.replaceAll(" order by id desc ", ""));
		request.setAttribute("list", fieldDao.selectBeanList((currentpage - 1)
				* pagesize, pagesize, where));
		request.setAttribute("pagerinfo", Pager.getPagerNormal(total, pagesize,
				currentpage, "method!fieldlist", "共有" + total + "条记录"));
		request.setAttribute("url", "method!fieldlist");
		request.setAttribute("url2", "method!field");
		request.setAttribute("biaoti", "澡堂管理");
		this.setUrl("field/fieldlist.jsp");
		return SUCCESS;

	}

//	跳转到添加澡堂页面
	public String fieldadd() {
		HttpServletRequest request = this.getRequest();
		request.setAttribute("url", "method!fieldadd2");
		request.setAttribute("biaoti", "澡堂添加");
		this.setUrl("field/fieldadd.jsp");
		return SUCCESS;
	}


//	添加澡堂操作
	public void fieldadd2() throws IOException {
		HttpServletRequest request = this.getRequest();
		PrintWriter writer = this.getPrintWriter();


		String bianhao = request.getParameter("bianhao");

		String mingchen = request.getParameter("mingchen");


		Field bean = fieldDao.selectBean(" where deletestatus=0 and bianhao='"+bianhao+"' ");

		if(bean!=null){

			writer.print("<script language=javascript>alert('操作失败，该澡堂编号已经存在');window.location.href='method!fieldlist';</script>");
			return;
		}

		bean = new Field();

		String[] weeks = request.getParameterValues("week");
		StringBuffer sb = new StringBuffer();

		if(weeks!=null&&weeks.length>0){
			for(int i=0;i<weeks.length;i++){
				sb.append(weeks[i]);
				if(i<weeks.length-1){
					sb.append(",");
				}
			}

		}

		bean.setWeek(sb.toString());


		String[] times = request.getParameterValues("time");
		StringBuffer sb2 = new StringBuffer();

		if(times!=null&&times.length>0){
			for(int i=0;i<times.length;i++){
				sb2.append(times[i]);
				if(i<times.length-1){
					sb2.append(",");
				}
			}

		}

		bean.setTime(sb2.toString());


		bean.setBianhao(bianhao);
		bean.setMingchen(mingchen);

		String renshu = request.getParameter("renshu");

		bean.setRenshu(Integer.parseInt(renshu));


		fieldDao.insertBean(bean);


		writer.print("<script language=javascript>alert('操作成功');window.location.href='method!fieldlist';</script>");


	}


//	跳转到更新澡堂页面
	public String fieldupdate() {
		HttpServletRequest request = this.getRequest();
		Field bean = fieldDao.selectBean(" where id= "
				+ request.getParameter("id"));

		if(bean.getWeek()!=null){
			String[] weeks = bean.getWeek().split(",");

			if(weeks!=null&&weeks.length>0){
				for(int i=0;i<weeks.length;i++){


					if("星期一".equals(weeks[i])){
						request.setAttribute("week1", "1");
					}
					if("星期二".equals(weeks[i])){
						request.setAttribute("week2", "1");
					}
					if("星期三".equals(weeks[i])){
						request.setAttribute("week3", "1");
					}
					if("星期四".equals(weeks[i])){
						request.setAttribute("week4", "1");
					}
					if("星期五".equals(weeks[i])){
						request.setAttribute("week5", "1");
					}
					if("星期六".equals(weeks[i])){
						request.setAttribute("week6", "1");
					}
					if("星期日".equals(weeks[i])){
						request.setAttribute("week7", "1");
					}
				}

			}

		}



		if(bean.getTime()!=null){
			String[] times = bean.getTime().split(",");

			if(times!=null&&times.length>0){
				for(int i=0;i<times.length;i++){


					if("09点到10点".equals(times[i])){
						request.setAttribute("time1", "1");
					}
					if("10点到11点".equals(times[i])){
						request.setAttribute("time2", "1");
					}
					if("11点到12点".equals(times[i])){
						request.setAttribute("time3", "1");
					}
					if("12点到13点".equals(times[i])){
						request.setAttribute("time4", "1");
					}
					if("13点到14点".equals(times[i])){
						request.setAttribute("time5", "1");
					}
					if("14点到15点".equals(times[i])){
						request.setAttribute("time6", "1");
					}
					if("15点到16点".equals(times[i])){
						request.setAttribute("time7", "1");
					}
					if("16点到17点".equals(times[i])){
						request.setAttribute("time8", "1");
					}
					if("17点到18点".equals(times[i])){
						request.setAttribute("time9", "1");
					}
					if("18点到19点".equals(times[i])){
						request.setAttribute("time10", "1");
					}
					if("19点到20点".equals(times[i])){
						request.setAttribute("time11", "1");
					}
					if("20点到21点".equals(times[i])){
						request.setAttribute("time12", "1");
					}
					if("21点到22点".equals(times[i])){
						request.setAttribute("time13", "1");
					}
					if("22点到23点".equals(times[i])){
						request.setAttribute("time14", "1");
					}
				}

			}

		}


		request.setAttribute("bean", bean);
		request.setAttribute("url", "method!fieldupdate2?id="+bean.getId());
		request.setAttribute("biaoti", "澡堂信息更新");
		this.setUrl("field/fieldupdate.jsp");
		return SUCCESS;
	}

//	更新澡堂操作
	public void fieldupdate2() throws IOException {
		HttpServletRequest request = this.getRequest();
		PrintWriter writer = this.getPrintWriter();


		String mingchen = request.getParameter("mingchen");


		Field bean = fieldDao.selectBean(" where id= "
				+ request.getParameter("id"));


		bean.setMingchen(mingchen);


		String[] weeks = request.getParameterValues("week");
		StringBuffer sb = new StringBuffer();

		if(weeks!=null&&weeks.length>0){
			for(int i=0;i<weeks.length;i++){
				sb.append(weeks[i]);
				if(i<weeks.length-1){
					sb.append(",");
				}
			}

		}

		bean.setWeek(sb.toString());


		String[] times = request.getParameterValues("time");
		StringBuffer sb2 = new StringBuffer();

		if(times!=null&&times.length>0){
			for(int i=0;i<times.length;i++){
				sb2.append(times[i]);
				if(i<times.length-1){
					sb2.append(",");
				}
			}

		}

		bean.setTime(sb2.toString());

		String renshu = request.getParameter("renshu");

		bean.setRenshu(Integer.parseInt(renshu));

		fieldDao.updateBean(bean);

		writer.print("<script language=javascript>alert('操作成功');window.location.href='method!fieldlist';</script>");
	}


//	删除澡堂操作
	public void fielddelete() throws IOException {
		HttpServletRequest request = this.getRequest();
		PrintWriter writer = this.getPrintWriter();
		Field bean = fieldDao.selectBean(" where id= "
				+ request.getParameter("id"));
		bean.setDeletestatus(1);
		fieldDao.updateBean(bean);



		writer.print("<script language=javascript>alert('操作成功');window.location.href='method!fieldlist';</script>");
	}



	//跳转到查看澡堂页面
	public String fieldupdate3() {
		HttpServletRequest request = this.getRequest();
		Field bean = fieldDao.selectBean(" where id= "
				+ request.getParameter("id"));
		request.setAttribute("bean", bean);
		request.setAttribute("biaoti", "澡堂查看");
		this.setUrl("field/fieldupdate3.jsp");
		return SUCCESS;
	}



	private YuyueDao yuyueDao;

	public YuyueDao getYuyueDao() {
		return yuyueDao;
	}

	public void setYuyueDao(YuyueDao yuyueDao) {
		this.yuyueDao = yuyueDao;
	}

	//澡堂列表
	public String fieldlist2() {
		HttpServletRequest request = this.getRequest();

		String bianhao = request.getParameter("bianhao");
		String mingchen = request.getParameter("mingchen");


		StringBuffer sb = new StringBuffer();
		sb.append(" where ");

		if (bianhao != null && !"".equals(bianhao)) {

			sb.append("bianhao like '%" + bianhao + "%'");
			sb.append(" and ");
			request.setAttribute("bianhao", bianhao);
		}

		if (mingchen != null && !"".equals(mingchen)) {

			sb.append("mingchen like '%" + mingchen + "%'");
			sb.append(" and ");
			request.setAttribute("mingchen", mingchen);
		}



		sb.append("   deletestatus=0   order by id desc ");
		String where = sb.toString();


		int currentpage = 1;
		int pagesize = 10;
		if (request.getParameter("pagenum") != null) {
			currentpage = Integer.parseInt(request.getParameter("pagenum"));
		}
		int total = fieldDao.selectBeanCount(where.replaceAll(" order by id desc ", ""));
		request.setAttribute("list", fieldDao.selectBeanList((currentpage - 1)
				* pagesize, pagesize, where));
		request.setAttribute("pagerinfo", Pager.getPagerNormal(total, pagesize,
				currentpage, "method!fieldlist2", "共有" + total + "条记录"));
		request.setAttribute("url", "method!fieldlist2");
		request.setAttribute("url2", "method!field");
		request.setAttribute("biaoti", "预约澡堂");
		this.setUrl("field/fieldlist2.jsp");
		return SUCCESS;

	}




	//选择预约日期
	public String fieldupdate5() throws ParseException {
		HttpServletRequest request = this.getRequest();
		Field bean = fieldDao.selectBean(" where id= "
				+ request.getParameter("id"));


		//可预约最近一周澡堂列表

		String riqi = Util.getRiqi2();//日期格式：20170106

		for(int i=1;i<8;i++){

			String riqi2 = (Integer.parseInt(riqi)+i)+"";


			String week = Util.getWeekOfDate(Util.parseRiqi2(riqi2));


			Field field = fieldDao.selectBean(" where id="+bean.getId()+" and week like '%"+week+"%' ");

			if(field!=null){
				
				if(field.getTime()!=null){
					
					String[] times = field.getTime().split(",");
					
					for(int j=0;j<times.length;j++){
						
						Yuyue yuyue = yuyueDao.selectBean(" where field.id="+field.getId()
								+" and riqi="+riqi2+" and week='"+week+"' and time like '%"+times[j]+"%' ");
						if(yuyue==null){
							yuyue = new Yuyue();
							yuyue.setTime(times[j]);
							yuyue.setField(field);
							yuyue.setRiqi(Integer.parseInt(riqi2));
							yuyue.setWeek(week);
							
							String rq = riqi2.substring(0, 4)+"-"+riqi2.substring(4, 6)+"-"+riqi2.substring(6, 8);
							
							yuyue.setRq(rq);
							
							yuyueDao.insertBean(yuyue);
							
							
						}
						
					}
					
					
					
				}
				
				


			}


		}

		request.setAttribute("bean", bean);
		
		
		
		String rq = request.getParameter("rq");
		String week = request.getParameter("week");
		String time = request.getParameter("time");
		
		

		StringBuffer sb = new StringBuffer();
		sb.append(" where ");

		if (week != null && !"".equals(week)) {

			sb.append("week like '%" + week + "%'");
			sb.append(" and ");
			request.setAttribute("week", week);
		}

		if (time != null && !"".equals(time)) {

			sb.append("time like '%" + time + "%'");
			sb.append(" and ");
			request.setAttribute("time", time);
		}
		
		if (rq != null && !"".equals(rq)) {

			sb.append("rq like '%" + rq + "%'");
			sb.append(" and ");
			request.setAttribute("rq", rq);
		}
		
		


		sb.append("   deletestatus=0  and field.id="+bean.getId()+"  and riqi>"+riqi+" and  riqi<"+(Integer.parseInt(riqi)+8)+" order by id  ");
		
		String where = sb.toString();


		int currentpage = 1;
		int pagesize = 9999;
		
		request.setAttribute("list", yuyueDao.selectBeanList((currentpage - 1)
				* pagesize, pagesize, where));
		
		


		request.setAttribute("biaoti", "您选择选择的澡堂编号"+bean.getBianhao()+",澡堂名称"+bean.getMingchen()+",请选择预约的日期时间段");

		this.setUrl("yuyue/yuyuelist.jsp");
		return SUCCESS;
	}



	private RecordDao recordDao;
	

	public RecordDao getRecordDao() {
		return recordDao;
	}

	public void setRecordDao(RecordDao recordDao) {
		this.recordDao = recordDao;
	}
	
	

	//预约澡堂操作
	public void fieldupdate6() throws IOException {
		HttpServletRequest request = this.getRequest();

		PrintWriter writer = this.getPrintWriter();
		
		

		String yuyueid = request.getParameter("yuyueid");
		

		Yuyue yuyue = yuyueDao.selectBean(" where id = "+yuyueid);
		
		if(yuyue.getField().getRenshu()-yuyue.getShiji()<=0){
			writer
			.print("<script language=javascript>alert('预约失败，该澡堂在该日期该时间段已经预约满');" +
					"window.location.href='method!fieldupdate5?id="+yuyue.getField().getId()+"';</script>");
			return ;
		}
		
	
		
		HttpSession session = request.getSession();
		User uu = (User)session.getAttribute("user");

		
		Record bean = recordDao.selectBean(" where deletestatus=0  and status='预约成功' and user.id="+uu.getId()+"  and riqi="+yuyue.getRiqi()+" ");
		
		if(bean!=null){
			writer
			.print("<script language=javascript>alert('预约失败，您已经在该日期预约过澡堂，不可重复预约');" +
					"window.location.href='method!fieldupdate5?id="+yuyue.getField().getId()+"';</script>");
			return ;
		}
		
		
		bean = new Record();
		bean.setUser(uu);
		bean.setYuyue(yuyue);
		bean.setYtime(Util.getTime());
		bean.setRiqi(yuyue.getRiqi());
		
		
		bean.setStatus("预约成功");
		recordDao.insertBean(bean);
		
		yuyue.setShiji(yuyue.getShiji()+1);
		
		yuyueDao.updateBean(yuyue);
		
		Tongji tongji = tongjiDao.selectBean(" where riqi='"+yuyue.getRq()+"' and field.id= "+yuyue.getField().getId());
		if(tongji==null){
			tongji = new Tongji();
			tongji.setField(yuyue.getField());
			tongji.setRiqi(yuyue.getRq());
			
			tongjiDao.insertBean(tongji);
		}
		
		
		tongji.setChenggong(tongji.getChenggong()+1);
		
		tongjiDao.updateBean(tongji);
		
		writer.print("<script language=javascript>alert('操作成功');window.location.href='method!recordlist';</script>");
		
		
		
	}
	
	
	//我的预约记录
	public String recordlist() {
		HttpServletRequest request = this.getRequest();

		String rq = request.getParameter("rq");
		String mingchen = request.getParameter("mingchen");


		StringBuffer sb = new StringBuffer();
		sb.append(" where ");

		if (rq != null && !"".equals(rq)) {

			sb.append(" yuyue.rq like '%" + rq + "%'");
			sb.append(" and ");
			request.setAttribute("rq", rq);
		}

		if (mingchen != null && !"".equals(mingchen)) {

			sb.append(" yuyue.field.mingchen like '%" + mingchen + "%'");
			sb.append(" and ");
			request.setAttribute("mingchen", mingchen);
		}

		HttpSession session = request.getSession();
		User uu = (User)session.getAttribute("user");

		sb.append("   deletestatus=0  and user.id="+uu.getId()+" order by id desc ");
		String where = sb.toString();


		int currentpage = 1;
		int pagesize = 10;
		if (request.getParameter("pagenum") != null) {
			currentpage = Integer.parseInt(request.getParameter("pagenum"));
		}
		int total = recordDao.selectBeanCount(where.replaceAll(" order by id desc ", ""));
		
		List<Record> list = recordDao.selectBeanList((currentpage - 1)* pagesize, pagesize, where);
		
		for(Record bean:list){
			
			
			if(bean.getRiqi()<=Integer.parseInt(Util.getRiqi2())){
				
				bean.setYystatus(1);
				
				recordDao.updateBean(bean);
			}
			
			
		}
		
		request.setAttribute("list",list );
		request.setAttribute("pagerinfo", Pager.getPagerNormal(total, pagesize,
				currentpage, "method!recordlist", "共有" + total + "条记录"));
		request.setAttribute("url", "method!recordlist");
		request.setAttribute("url2", "method!record");
		request.setAttribute("biaoti", "我的预约记录");
		
	
		
		this.setUrl("record/recordlist.jsp");
		return SUCCESS;

	}
	
	
	

//	取消预约操作
	public void recorddelete() throws IOException {
		HttpServletRequest request = this.getRequest();
		PrintWriter writer = this.getPrintWriter();
		Record bean = recordDao.selectBean(" where id= "
				+ request.getParameter("id"));

		bean.setStatus("取消预约");
		
		recordDao.updateBean(bean);

		Yuyue yuyue = yuyueDao.selectBean(" where id= "+bean.getYuyue().getId());
		
		yuyue.setShiji(yuyue.getShiji()-1);
		
		yuyueDao.updateBean(yuyue);
		
		
		Tongji tongji = tongjiDao.selectBean(" where riqi='"+yuyue.getRq()+"' and field.id= "+yuyue.getField().getId());
		if(tongji==null){
			tongji = new Tongji();
			tongji.setField(yuyue.getField());
			tongji.setRiqi(yuyue.getRq());
			
			tongjiDao.insertBean(tongji);
		}
		
		
		tongji.setChenggong(tongji.getChenggong()-1);
		
		tongji.setQuxiao(tongji.getQuxiao()+1);
		
		tongjiDao.updateBean(tongji);

		writer.print("<script language=javascript>alert('操作成功');window.location.href='method!recordlist';</script>");
	}
	

	//预约记录查询
	public String recordlist2() {
		HttpServletRequest request = this.getRequest();

		String rq = request.getParameter("rq");
		String mingchen = request.getParameter("mingchen");
		
		String xingming = request.getParameter("xingming");


		StringBuffer sb = new StringBuffer();
		sb.append(" where ");

		if (rq != null && !"".equals(rq)) {

			sb.append(" yuyue.rq like '%" + rq + "%'");
			sb.append(" and ");
			request.setAttribute("rq", rq);
		}

		if (mingchen != null && !"".equals(mingchen)) {

			sb.append(" yuyue.field.mingchen like '%" + mingchen + "%'");
			sb.append(" and ");
			request.setAttribute("mingchen", mingchen);
		}
		
		if (xingming != null && !"".equals(xingming)) {

			sb.append(" user.xingming like '%" + xingming + "%'");
			sb.append(" and ");
			request.setAttribute("xingming", xingming);
		}

		

		sb.append("   deletestatus=0 order by id desc ");
		String where = sb.toString();


		int currentpage = 1;
		int pagesize = 10;
		if (request.getParameter("pagenum") != null) {
			currentpage = Integer.parseInt(request.getParameter("pagenum"));
		}
		int total = recordDao.selectBeanCount(where.replaceAll(" order by id desc ", ""));
		
		List<Record> list = recordDao.selectBeanList((currentpage - 1)* pagesize, pagesize, where);
		
		
		request.setAttribute("list",list );
		request.setAttribute("pagerinfo", Pager.getPagerNormal(total, pagesize,
				currentpage, "method!recordlist2", "共有" + total + "条记录"));
		request.setAttribute("url", "method!recordlist2");
		request.setAttribute("url2", "method!record");
		request.setAttribute("biaoti", "预约记录查询");
		
	
		
		this.setUrl("record/recordlist2.jsp");
		return SUCCESS;

	}
	
	
	private TongjiDao tongjiDao;

	public TongjiDao getTongjiDao() {
		return tongjiDao;
	}

	public void setTongjiDao(TongjiDao tongjiDao) {
		this.tongjiDao = tongjiDao;
	}
	
	
	//预约统计
	public String tongjilist() {
		HttpServletRequest request = this.getRequest();

		
		String riqi = request.getParameter("riqi");
		
		String mingchen = request.getParameter("mingchen");


		StringBuffer sb = new StringBuffer();
		sb.append(" where ");

		if (riqi != null && !"".equals(riqi)) {

			sb.append(" riqi like '%" + riqi + "%'");
			sb.append(" and ");
			request.setAttribute("riqi", riqi);
		}

		if (mingchen != null && !"".equals(mingchen)) {

			sb.append(" field.mingchen like '%" + mingchen + "%'");
			sb.append(" and ");
			request.setAttribute("mingchen", mingchen);
		}
		

		sb.append("   0=0 order by id desc ");
		String where = sb.toString();


		int currentpage = 1;
		int pagesize = 10;
		if (request.getParameter("pagenum") != null) {
			currentpage = Integer.parseInt(request.getParameter("pagenum"));
		}
		int total = tongjiDao.selectBeanCount(where.replaceAll(" order by id desc ", ""));
		
		List<Tongji> list = tongjiDao.selectBeanList((currentpage - 1)* pagesize, pagesize, where);
		
		
		request.setAttribute("list",list );
		request.setAttribute("pagerinfo", Pager.getPagerNormal(total, pagesize,
				currentpage, "method!tongjilist", "共有" + total + "条记录"));
		request.setAttribute("url", "method!tongjilist");
		request.setAttribute("url2", "method!tongji");
		request.setAttribute("biaoti", "预约统计");
		
	
		
		this.setUrl("tongji/tongjilist.jsp");
		return SUCCESS;

	}
	
}
